package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityPrizeDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityPrizeMapper {
//    @Insert("<script>" +
//            "insert into activity_prize (activity_id,prize_amount,prize_id,prize_tiers,status)" +
//            "values " +
//            " <foreach collection='items',item='item',index='index',separator=','>" +
//            "(#{item.activityId},#{item.prizeAmount},#{item.prizeId},#{item.prizeTiers},#{item.status})" +
//            "</foreach>" +
//            "</script>")
//    @Options(useGeneratedKeys = true, keyProperty = "id",keyColumn = "id")
//    void BatchInsert(List<ActivityPrizeDO> activityPrizeDOList);

    @Insert("<script>" +
            "insert into activity_prize (activity_id, prize_amount, prize_id, prize_tiers, status) " +
            "values " +
            "<foreach collection='list' item='item' separator=','>" +
            "(#{item.activityId}, #{item.prizeAmount}, #{item.prizeId}, #{item.prizeTiers}, #{item.status})" +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void BatchInsert(@Param("list") List<ActivityPrizeDO> activityPrizeDOList);

    @Select("select count(*) from activity_prize where activity_id = #{activityId} and status = #{status}")
    Integer countPrize(@Param("activityId") Long activityId,@Param("status") String status);

    @Select("select * from activity_prize where activity_id = #{activityId} and prize_id = #{prizeId}")
    ActivityPrizeDO selectByAPId(@Param("activityId") Long activityId,@Param("prizeId") Long prizeId);

    @Update("update activity_prize set status = #{status} where activity_id = #{activityId} and prize_id = #{prizeId}")
    void updateStatus(@Param("activityId") Long activityId, @Param("prizeId") Long prizeId,@Param("status") String status);
}
